package com.yuanthink.gwt.client.workplace;

import java.util.List;

import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
import com.google.gwt.user.client.ui.Widget;
import com.yuanthink.gwt.client.eventbus.EventBus;
import com.yuanthink.gwt.client.registry.GeneralRegistry;

/**
 * 
 * @author 06peng
 * 
 */
public class MainWorkplaceView extends LayoutContainer implements
		WorkspacePresenter.Display {

	Navigator navigator;
	ContentPanel mainArea;
	EventBus eventBus;
	
	public MainWorkplaceView(EventBus eventBus) {
		this.eventBus = eventBus;
		final BorderLayout layout = new BorderLayout();
		layout.setEnableState(true);

		setLayout(layout);
		setStyleAttribute("padding", "3px");
		navigator = new Navigator(eventBus);
		navigator.setStateful(true);
		GeneralRegistry.put("navigator", navigator);

		BorderLayoutData westData = new BorderLayoutData(
				Style.LayoutRegion.WEST, 200);
		westData.setSplit(true);
		westData.setCollapsible(true);
		westData.setMargins(new Margins(0, 5, 0, 0));

		BorderLayoutData centerData = new BorderLayoutData(
				Style.LayoutRegion.CENTER);
		centerData.setMargins(new Margins(0));

		ContentPanel rightPanel = new ContentPanel();

		// BorderLayoutData mainNorthData = new
		// BorderLayoutData(Style.LayoutRegion.NORTH, 30);
		// mainNorthData.setMargins(new Margins(0, 0, 5, 0));
		// MainWorkplaceNorthPresenter mainWorkplaceNorthPresenter = new
		// MainWorkplaceNorthPresenter(eventBus);
		//
		// add(mainWorkplaceNorthPresenter.display,mainNorthData);
		add(navigator, westData);
		add(rightPanel, centerData);

		rightPanel.setLayout(new BorderLayout());

		mainArea = new ContentPanel();
		mainArea.setBodyBorder(false);
		mainArea.setBorders(false);
		mainArea.setHeaderVisible(false);
		mainArea.setScrollMode(Style.Scroll.AUTO);
		rightPanel.add(mainArea, centerData);
		rightPanel.setHeaderVisible(false);
		rightPanel.setBodyStyle("border-top:0px;");

		GeneralRegistry.put("mainArea", mainArea);

		ToolBar toolBar = new ToolBar();
		toolBar.setHeight(28);
		rightPanel.setTopComponent(toolBar);
		GeneralRegistry.put("columnMenuToolBar", toolBar);

	}

	@Override
	public void setWorkspaces(List<ModelData> result) {

	}

	@Override
	public void setAction(String action) {

	}

	@Override
	public Widget getNavigator() {
		return navigator;
	}

	@Override
	public TreePanel<ModelData> getTree() {
		return navigator.getTreePanel();
	}

	@Override
	public Widget getMainArea() {
		return mainArea;
	}
	
	@Override
	public void setCurrentWorkspace(ModelData config) {
        navigator.setCurrentWorkspace(config);
    }

}
